package com.example.wanted.controller;

import com.example.wanted.model.Like_star;
import com.example.wanted.service.Like_starService;
import com.example.wanted.service.CommentService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class Like_starController {
    final Like_starService like_starService;

    @Autowired
    public Like_starController(Like_starService like_starService) {
        this.like_starService = like_starService;
    }

    @PostMapping("like_star")
    public void saveLike_star(@RequestBody Like_star l, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(l);
        like_starService.save(l);
    }

    @GetMapping("get_like")
    public boolean getLike_Question(@RequestParam String user_id, @RequestParam Long question_id, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(question_id);
        System.out.println(user_id);
        return like_starService.findLikeByUserAndQuestion(user_id, question_id);
    }


    @GetMapping("get_star")
    public boolean getStar_Question(@RequestParam String user_id, @RequestParam Long question_id, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(question_id);
        System.out.println(user_id);
        return like_starService.findStarByUserAndQuestion(user_id, question_id);
    }

    @GetMapping("can_get_like_star")
    public boolean getLikeStar_Question(@RequestParam String user_id, @RequestParam Long question_id, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(question_id);
        System.out.println(user_id);
        return like_starService.canfindByUserAndQuestion(user_id, question_id);
    }

    @GetMapping("get_like_star")
    public Like_star get(@RequestParam String user_id, @RequestParam Long question_id, HttpServletResponse res, HttpServletRequest req){
        return like_starService.findByUserAndQuestion(user_id, question_id);
    }

    @PostMapping("update_like_star")
    public void updateLikeStar(@RequestBody Like_star like_star, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(like_star);
        like_starService.updateByUserAndQuestion(like_star);
    }

}
